package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	version1 := "0.1"
	version2 := "1.001.0"
	fmt.Println(compareVersion(version1, version2))

}

//#link : https://leetcode-cn.com/problems/compare-version-numbers/
func compareVersion(version1 string, version2 string) int {
	//1>2 return 1
	version1Split := strings.Split(version1, ".")
	version2Split := strings.Split(version2, ".")
	//version2 长的时候
	len1, len2 := len(version1Split), len(version2Split)
	if len1 < len2 {
		for i := 0; i < len2-len1; i++ {
			version1Split = append(version1Split, "0")
		}
	} else {
		for i := 0; i < len1-len2; i++ {
			version2Split = append(version2Split, "0")
		}
	}
	for i := 0; i < len(version1Split); i++ {
		a, _ := strconv.Atoi(version1Split[i])
		b, _ := strconv.Atoi(version2Split[i])
		if a < b {
			return -1
		} else if a > b {
			return 1
		}
	}
	return 0
}
